import { validate } from "class-validator";

export default class BaseEntity {
  /**
   * 验证用户实体类的字段完整性与正确性
   * @returns 
   */
  public async validateThie(skpiMissing: boolean = false): Promise<string[]> {
    const errors = await validate(this, {
      skipUndefinedProperties: skpiMissing // 验证配置，跳过缺失的的属性，编辑时跳过(true),添加时不跳过(false)
    });
    const errorArr = errors.map(e => Object.values(e.constraints!));
    const arr: string[] = [];
    errorArr.forEach(item => {
      arr.push(...item)
    })
    return arr;
  }

}
